package com.wjd.gulimall.product.controller;

import com.wjd.common.utils.PageUtils;
import com.wjd.common.utils.R;
import com.wjd.gulimall.product.dto.AttrDto;
import com.wjd.gulimall.product.service.AttrService;
import com.wjd.gulimall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 商品属性
 *
 * @author weijiaduo
 * @email jiaduo.wei@gmail.com
 * @date 2025-05-24 16:46:00
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {

    @Autowired
    private AttrService attrService;

    /**
     * 分类列表
     */
    @RequestMapping("/{attrType}/list/{catelogId}")
    // @RequiresPermissions("product:attr:list")
    public R categoryList(@PathVariable String attrType, @PathVariable Long catelogId
            , @RequestParam Map<String, Object> params) {
        params.put("attrType", attrType);
        params.put("catelogId", catelogId);
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    // @RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId) {
        AttrVo attr = attrService.getAttr(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrDto attr) {
        attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrDto attr) {
        attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds) {
        attrService.deleteAttrs(Arrays.asList(attrIds));

        return R.ok();
    }

}
